package com.itheima.controller.admin;

import com.itheima.common.result.Result;
import com.itheima.dto.YddAdvposDTO;
import com.itheima.mapper.YddAdvposMapper;
import com.itheima.pojo.YddAdvpos;
import com.itheima.service.IYddAdvposService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class YddAdvposController {
    @Autowired
    private IYddAdvposService yddAdvposService;
    @Autowired
    private YddAdvposMapper yddAdvposMapper;

    /**
     * 广告位列表分页
     * @param dto
     * @return
     */
    @GetMapping( "/ydd_advpos/list")
    public Result listAdvpos(YddAdvposDTO dto){
        log.info("广告位列表分页查询");
        return Result.success(yddAdvposService.listAdvpos(dto));
    }

    /**
     * 广告位修改
     * @param yddAdvpos
     * @return
     */
    @PostMapping("/ydd_advpos/update")
    public Result updateAdvpos(@RequestBody YddAdvpos yddAdvpos){
        log.info("广告位修改");
        yddAdvposService.updateAdvpos(yddAdvpos);
        return Result.success();
    }

    /**
     * 广告位详情
     * @param id
     * @return
     */
    @GetMapping("/ydd_advpos/rowInfo")
    public Result rowInfo(Integer id){
        YddAdvpos yddAdvpos = yddAdvposService.rowInfo(id);
        return Result.success(yddAdvpos);
    }

    /**
     * 删除广告位
     * @param id
     * @return
     */
    @GetMapping("/ydd_advpos/del")
    public Result deleteAdvpos(Integer id){
        yddAdvposService.deleteAdvpos(id);
        return Result.success();
    }

    /**
     * 新增广告位
     * @param yddAdvpos
     * @return
     */
    @PostMapping("/ydd_advpos/add")
    public Result addAdvpos(@RequestBody YddAdvpos yddAdvpos){
        yddAdvposMapper.insert(yddAdvpos);
        return Result.success();
    }
    @GetMapping("/ydd_advpos/all")
    public Result allAdvpos(){
        List<YddAdvpos> yddAdvpos = yddAdvposMapper.selectList(null);
        return Result.success(yddAdvpos);
    }
}
